package com.i72.basic.context;

import com.i72.basic.enums.EnvironmentEnum;
import com.i72.basic.enums.RPCProtocolEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * 上下文全局变量
 */
public class GlobalContext {

    private final static Map<String,Object> map = new HashMap();

    public final static String PROTOCOL = "PROTOCOL";
    public final static String IP = "IP";
    public final static String PORT = "PORT";
    public final static String ENVIRONMENT = "ENVIRONMENT";
    public final static String REGISTER = "REGISTER";
    public final static String SUBSCRIBE = "SUBSCRIBE";
    public final static String APPNAME = "APPNAME";
    public final static String APPPACKAGE = "APPPACKAGE";
    public final static String SUBSCRIBELIST = "SUBSCRIBELIST";
    public final static String CONFIG_REFRESH_TIMESPAN="CONFIG_REFRESH_TIMESPAN";

    static {
        map.put(PROTOCOL, RPCProtocolEnum.HTTP.name());
        map.put(IP, "");
        map.put(PORT, "");
        map.put(ENVIRONMENT, EnvironmentEnum.LOCAL.name());
        map.put(REGISTER,true);
        map.put(SUBSCRIBE,true);
        map.put(APPNAME,"");
        map.put(APPPACKAGE,"");
    }

    public static String getProtocol(){
        return map.get(PROTOCOL).toString();
    }

    public static void setProtocol(String protocol){
        map.put(PROTOCOL,protocol);
    }

    public static boolean getSubscribe(){
        return (boolean)map.get(SUBSCRIBE);
    }

    public static void setSubscribe(boolean subscribe){
        map.put(SUBSCRIBE,subscribe);
    }

    public static boolean getRegister(){
        return (boolean)map.get(REGISTER);
    }

    public static void setRegister(boolean register){
        map.put(REGISTER,register);
    }

    public static String getIP(){
        return map.get(IP).toString();
    }

    public static void setIP(String ip){
        map.put(IP,ip);
    }

    public static String getPort(){
        return map.get(PORT).toString();
    }

    public static void setPort(Integer port){
        map.put(PORT,port);
    }

    public static String getEnvironment(){
        return map.get(ENVIRONMENT).toString();
    }

    public static void setEnvironment(String environment){
        map.put(ENVIRONMENT,environment);
    }

    public static String getAPPName(){
        return map.get(APPNAME).toString();
    }

    public static void setAPPName(String appName){
        map.put(APPNAME,appName);
    }

    public static String getAPPPackage(){
        return map.get(APPPACKAGE).toString();
    }

    public static void setAPPPackage(String appName){
        map.put(APPPACKAGE,appName);
    }

    public static void setSubscribelist(String subscribelist){ map.put(SUBSCRIBELIST,subscribelist); }
    public static String getSubscribelist(){
        return map.get(SUBSCRIBELIST).toString();
    }

    public static String getConfigRefreshTimespan(){
        return map.get(CONFIG_REFRESH_TIMESPAN).toString();
    }
    public static void setConfigRefreshTimespan(String configRefreshTimespan){
        map.put(CONFIG_REFRESH_TIMESPAN,configRefreshTimespan);
    }


}
